package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.LogAnno;
import com.example.common.Result;
import com.example.common.enums.LogType;
import com.example.pojo.entity.Assessment;
import com.example.pojo.entity.Cost;
import com.example.service.AssessmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/assessment")
@Api(tags = "质量评估接口")
public class AssessmentController {

    @Autowired
    private AssessmentService assessmentService;
    @ApiOperation("新增质量评估信息")
    @LogAnno(title = "质量管理", type = LogType.ADD)
    @PostMapping("/add")
    public Result add(@ApiParam("质量评估信息") @RequestBody Assessment assessment) {
        assessmentService.add(assessment);
        return Result.success();
    }

    @ApiOperation("通过Id获取质量评估信息")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Assessment assessment = assessmentService.getById(id);
        return Result.success(assessment);
    }
    @ApiOperation("分页展示质量评估信息列表")
    @GetMapping("/selectPage")
    public Result selectPage(String name,
                             @ApiParam("当前页数") @RequestParam(defaultValue = "1") Integer pageNum,
                             @ApiParam("页面数据大小") @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<Assessment> page = assessmentService.selectPage(name,pageNum, pageSize);

        return Result.success(page);
    }
    @ApiOperation("根据ID批量删除质量评估信息")
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        assessmentService.deleteBatch(ids);
        return Result.success();
    }
    @ApiOperation("通过Id删除质量评估信息")
    @LogAnno(title = "质量管理", type = LogType.DELETE)
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        assessmentService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("更新成本费用信息")
    @LogAnno(title = "成本管理", type = LogType.UPDATE)
    @PutMapping("/update")
    public Result update(@RequestBody Assessment assessment) {
        assessmentService.update(assessment);
        return Result.success();
    }

}
